home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
362_01
/
rmaxtask.doc
< prev
next >
Wrap
Text File
|
1991-12-11
|
54KB
|
1,104 lines
RMAXTask
A Multitasking Environment for C and C++
Version 1.0
---
Copyright (c) 1991
RMAX Development Group
1033 East Coral Gables Drive
Phoenix, Arizona 85022
Page 1
TABLE OF CONTENTS
-----------------
LEGAL INFORMATION . . . . . . . . . . . . . . . . . . . 2
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . 3
What is RMAXTask? . . . . . . . . . . . . . . . . . 3
What is Multitasking? . . . . . . . . . . . . . . . 3
Why Do I Need Multitasking? . . . . . . . . . . . . 4
RMAXTask TECHNICAL INFORMATION . . . . . . . . . . . . 8
How Does RMAXTask Work? . . . . . . . . . . . . . . 8
RMAXTask Function Overviews . . . . . . . . . . . . 9
RMAXTask FUNCTION REFERENCE . . . . . . . . . . . . . . 12
check_mail() . . . . . . . . . . . . . . . . . . . . 12
check_sem() . . . . . . . . . . . . . . . . . . . . 12
create_mailbox() . . . . . . . . . . . . . . . . . . 12
create_sem() . . . . . . . . . . . . . . . . . . . . 12
create_task(). . . . . . . . . . . . . . . . . . . . 13
fake_key() . . . . . . . . . . . . . . . . . . . . . 14
get_mail() . . . . . . . . . . . . . . . . . . . . . 14
get_status() . . . . . . . . . . . . . . . . . . . . 15
key_hit() . . . . . . . . . . . . . . . . . . . . . 15
kill_task() . . . . . . . . . . . . . . . . . . . . 15
RMAX_time() . . . . . . . . . . . . . . . . . . . . 16
send_mail() . . . . . . . . . . . . . . . . . . . . 16
signal_sem() . . . . . . . . . . . . . . . . . . . . 16
start_RMAXTask() . . . . . . . . . . . . . . . . . . 17
stop_RMAXTask() . . . . . . . . . . . . . . . . . . 17
suspend() . . . . . . . . . . . . . . . . . . . . . 17
wait_key() . . . . . . . . . . . . . . . . . . . . . 18
wait_sem() . . . . . . . . . . . . . . . . . . . . . 18
yield() . . . . . . . . . . . . . . . . . . . . . . 19
RMAXTask QUESTIONS AND ANSWERS . . . . . . . . . . . . 20
APPENDIX A - IBM PC EXTENDED KEYBOARD CODES . . . . . . 22
APPENDIX B - RMAXTask REVISION HISTORY . . . . . . . . 24
Page 2
LEGAL INFORMATION
-----------------
This is the RMAXTask multitasking library for C. This
library is copyrighted, but you may use and distribute the
shareware version of the library under the following
conditions:
1. By using the library, you agree that you do so at your
own risk, and to hold both RMAX Development Group and the
authors of these programs harmless from any liability for
loss or damage of any kind suffered by you arising from
your use of these programs.
2. You may freely copy and distribute the shareware files,
provided that you distribute them all together in their
original form, without any changes, additions or
deletions. No fee may be charged for distributing the
files, except that you may charge not more than a $10.00
disk copying fee for each physical copy you distribute.
3. You may not create programs intended for sale using the
RMAXTask library unless you have registered your copy,
nor may you continue to use the shareware files for more
than 30 days after receiving them without registering.
Upon registration, you will receive the full source code
to the library, pre-compiled libraries for all the memory
models for both C and C++, and a license allowing
unrestricted use of the library routines in your own
programs.
To register your copy of RMAXTask, simply fill out the form
found in the file REGISTER.TXT and return it along with your
registration fee.
Page 3
WHAT IS RMAXTask?
-----------------
RMAXTask is a library of C functions that lets you run one or
more C functions together in a priority-based, cooperative
(non-preemptive) multitasking environment. RMAXTask
provides full support for intertask synchronization and
communication, timed delays, and access to the PC's keyboard.
RMAXTask provides a more capable scheduler and better
intertask communication than do simple round-robin task
switchers such as Wayne Conrad's MTASK or the system
described in the October, 1988 issue of "Computer Language"
magazine, while avoiding the complexity of a full-blown
interrupt-driven, preepmtive system like Thomas Wagner's
CTask.
WHAT IS MULTITASKING?
---------------------
Multitasking is a way to divide a single program into several
distinct threads of execution called "tasks" which execute
concurrently under the control of a supervisory program
called a "scheduler". The tasks are usually somewhat
independent of one another (although they can communicate
among themselves) and appear to execute all at once. On a
single-CPU system, of course, only one task can be running at
any given instant, but the scheduler passes control to the
various tasks in a way that gives the illusion that they are
all running at the same time.
Multitasking as implemented by RMAXTask is not to be confused
with multiprogramming (as provided by Windows or an operating
system like QNX), in which multiple -programs- appear to run
at the same time, or with multiprocessing, which requires a
computer with more than one CPU. When you use RMAXTask, you
compile and link all your tasks together into a single
program which appears (and is) to the operating system just
like any other program.
PREEMPTIVE VS. COOPERATIVE MULTITASKING
---------------------------------------
In a "preemptive" multitasking system, the scheduler doles
out CPU time to the tasks in chunks called "time slices".
Each task is allowed to execute for a specific time period,
after which control is wrested from it by the timer interrupt
and given to some other task by the scheduler. The advantage
of such a scheme is that tasks can be written with little or
no awareness of the multitasking system. The downside,
however, is that it can be difficult to make sure that tasks
Page 4
are not interrupted at inappropriate times. As an example,
consider a task which has just made a DOS call to write to a
file. If it is interrupted while it is within DOS and
control is then passed to a different task which also calls
DOS, havoc will reign shortly because DOS is not re-entrant.
In a "cooperative" multitasking environment, a task once
running continues to run until it explicitly relinquishes
control by making a call to the multitasking system. As a
result, such tasks must be wr